from pathlib import Path

path = Path('10_chapter_10_test\guest_book.txt')

names = ''
while True:
    name = input("请输入名字，输入 quit 退出：")
    if name.lower() == 'quit':
        break
    else:
        names += name + '\n'

path.write_text(names.title().rstrip('\n'))